import { FC, useRef } from "react";

const Demo: FC = () => {
  const inputRef = useRef<HTMLInputElement>(null);

  function selectInput() {
    const inputEle = inputRef.current;
    inputEle && inputEle.select();
  }

  return (
    <div>
      <input ref={inputRef} defaultValue="hello world" />
      <button onClick={selectInput}> 点击选中</button>
    </div>
  );
};

export default Demo;
